package cn.hj.basic.controller;


import cn.hj.basic.exception.BusinessException;
import cn.hj.basic.service.IVerifyCodeService;
import cn.hj.basic.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/verifycode")
public class VerifyCodeController {

    @Autowired
    private IVerifyCodeService verifyCodeService;

    @PostMapping("/sendSmsCode")
    public AjaxResult sendSmsCode(@RequestBody Map<String,String> params){
        try {
            verifyCodeService.sendSmsCode(params);
            return AjaxResult.newAjaxResult();
        }catch (BusinessException e){
            e.printStackTrace();
            return AjaxResult.newAjaxResult().setSuccess(false).setMessage(e.getMessage());
        }catch (Exception e){
            e.printStackTrace();
            return AjaxResult.newAjaxResult().setSuccess(false).setMessage("系统错误，我们正在殴打程序员");
        }
    }
}
